package cn.qyd.javathread;

/**
 * @author 邱运铎
 * @date 2024-03-14 17:15
 */
public class YuanZiXingDemo {
    private static int i = 0;
    public static void main(String[] args) throws InterruptedException {
        final int nThread = 2;
        final int nIncrementNumber = 10000;

        Thread[] threads = new Thread[nThread];

        for (int j = 0; j < nThread; j++) {
            threads[j] = new Thread(() -> {
                for (int k = 0; k < nIncrementNumber; k++) {
                    i++;
                }
            });
            threads[j].start();
        }

        for (Thread thread : threads) {
            thread.join();
        }

        System.out.println("i经过1万次的自增后实际值为： " + i);
        System.out.println("i经过一万次自增后预期值为： " + (nThread * nIncrementNumber));
    }
}
